//
//  BDMapController.m
//  oc1
//
//  Created by kokuma on 2017/2/18.
//  Copyright © 2017年 kokumams. All rights reserved.
//30.3, 120.2

#import "BDMapController.h"
#import <BaiduMapAPI_Map/BMKMapComponent.h>

@interface BDMapController ()
@property (strong, nonatomic)BMKMapView* mapView;
@end

@implementation BDMapController
UIButton* _zoom;
UIButton* _rotate;
UIButton* _overlook;

UIButton* _closeButton;
UIImageView* _imgView;



- (void)viewDidLoad {
    [super viewDidLoad];
    //适配ios7
    if( ([[[UIDevice currentDevice] systemVersion] doubleValue]>=7.0))
    {
        //        self.edgesForExtendedLayout=UIRectEdgeNone;
        self.navigationController.navigationBar.translucent = NO;
    }
    //初始化右边的更新按钮
    UIBarButtonItem *customRightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"截图" style:UIBarButtonItemStyleBordered target:self action:@selector(snapshot)];
    customRightBarButtonItem.title = @"截图";
    self.navigationItem.rightBarButtonItem = customRightBarButtonItem;
    CGSize size = self.view.bounds.size;
    _mapView =[[BMKMapView alloc]initWithFrame:CGRectMake(10, 10, size.width-20, size.height-20)];
    [self.view addSubview:_mapView];
    [self nailMoveAndZoom2HZ];
}

//钉子定在某点，地图放大，同时钉子摆在屏幕中间
-(void)nailMoveAndZoom:(double)lat lng:(double)lng isZoom:(BOOL)isZoom {
    //设置缩放级别
    float targetZoomLevel = 16;
    if(_mapView.zoomLevel>targetZoomLevel){
        targetZoomLevel=_mapView.zoomLevel;
    }
    if(isZoom){
        BMKMapStatus *status = [[BMKMapStatus alloc]init];
        status.fLevel = targetZoomLevel;
        [_mapView setMapStatus:status withAnimation:true];
    }
    [_mapView setCenterCoordinate:CLLocationCoordinate2DMake(lat,lng)];
}

-(void)nailMoveAndZoom2HZ{
    [self nailMoveAndZoom:30.3 lng:120.2 isZoom:true];
}

-(void)viewWillAppear:(BOOL)animated {
    [_mapView viewWillAppear];
    _mapView.delegate = self; // 此处记得不用的时候需要置nil，否则影响内存的释放
}

-(void)viewWillDisappear:(BOOL)animated {
    [_mapView viewWillDisappear];
    _mapView.delegate = nil; // 不用时，置nil
}
- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}
- (void)dealloc {
    if (_mapView) {
        _mapView = nil;
    }
}

@end
